export default {
    data() {
        return {
            feedback_id:0,
            radio:'2',
            detail_data:'',
            content:"",
            userList:[],
            value:""
        }
    },
    //进入页面加载
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }
        if(that.$route.query.feedback_id) {
            that.feedback_id = that.$route.query.feedback_id;
            that.detail();
            that.getUserList();
        }
    },

    methods: {
        /**
         * 意见详情
         */
        detail: function() {
            let that = this;
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/opinion/ollowf_up", {
                token: that.token,
                id: that.feedback_id,
            }, {
                emulateJSON: true
            }).then(
                function(res) {
                    // 处理成功的结果
                    that.detail_data = res.body;
                },
                function() {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        /**
         * 提交处理
         */
        sendContent:function () {
            let that = this;
            if(that.content === ''){
                // 处理失败的结果
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '请输入处理说明' }`
                });
                return false;
            }
            if(that.value === ''){
                // 处理失败的结果
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '请选择处理人员' }`
                });
                return false;
            }
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/api/opinion/addollowf", {
                token: that.token,
                feedback_id: that.feedback_id,
                content:that.content,
                status:that.radio,
                system_manager_id:that.value
            }, {
                emulateJSON: true
            }).then(
                function(res) {
                    that.$message({
                        type: 'success',
                        message: `操作提示: ${ '处理成功' }`
                    });
                    that.detail();
                },
                function() {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        /**
         * 加载所有管理员
         */
        getUserList:function () {
            let that = this;
            that.$http.post(that.adminApi.api_url + "/api/manager/index", {
                token: that.token,
                id:that.user_id
            }, {
                emulateJSON: true
            }).then(
                function(res) {
                    let body = res.body.list;
                    if (body.count > 0) {
                        for (let i in body.list) {
                            that.userList.push({
                                'value': body.list[i].id,
                                'label': body.list[i].truename
                            });
                        }
                    }
                },
                function() {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },


        /**
         * 返回
         */
        cancelFeed:function () {
            let that =this;
            that.$router.back(-1);
        }
    }
}